
/*测试布尔值*/
testBool() {
	print("====test Bool");
	var fullName = "";
	if (fullName.isEmpty) {
		print("fullName is Empty");
	}

	var hitPoints = 0;
	if (hitPoints <= 0) {
		print("hitPoints is Zero");
	}

	var isMeantToDoThie = 0 / 0;
	if (isMeantToDoThie.isNaN) {
		print("isMeantToDoThie is isNaN");
	}
}

/*测试容器*/
testContainer() {
	var list = [1, 2, 3];
	print("lists = $list");

	var unMutableList = const [1, 2];
	print("length = ${unMutableList.length}");
	// unMutableList[0] = 0;//Cannot modify an unmodifiable list

	var map = {
		1: "one",
		2: "two"
	};
	print("map = $map");
	print("map[0] = ${map[0]}");
	print("map[1] = ${map[1]}");
	if (map[100] == null) {
		print("map[100] not found");
	}
}

/////////// 方法


String say(String from, String msg, [String device]) {
	var result = '$from says $msg';
	if (device != null) {
		result = '$result with a $device';
	}
	return result;
}


testFun() {
	print(say("pauhu", "hello daxiong"));
	print(say("pauhu", "hello daxiong", "feiji"));
}

testAnonymousFun() {
	var list = ["one", "two", "three"];
	list.forEach((i){
		print("indexof ${i} = ${list.indexOf(i)}");
	});
	list.forEach((i) => print("indexof ${i} = ${list.indexOf(i)}"));

	var add2 = makeAdder(2);
	print("add2(1) = ${add2(1)}");
}

Function makeAdder(num addBy) {
	return (num i) {
		return addBy + i;
	};
}

/////////// 操作
testOperation() {
	var fatherObj = new MyFatherObj();
	var sonObj = new MySonObj();
	var obj1 = new MyOtherObj();

	if (fatherObj is MyFatherObj) {
		print("=fatherObj is MyFatherObj");
	} else {
		print("=fatherObj is not MyFatherObj");
	}

	if (fatherObj is MySonObj) {
		print("=fatherObj is MySonObj");
	} else {
		print("=fatherObj is not  MySonObj");
	}
}

class MyFatherObj extends Object{

}

class MySonObj extends MyFatherObj{

}

class MyOtherObj extends Object{

}


/////////// 操作
testException() {
	try {
		throsExceptionFun();
	} on Exception catch(e, stack) {
		print("catch Exception e = $e  stack = $stack");
	} catch(e, stack) {
		print("catch e = $e  stack = $stack");
	} finally {
		print("finally");
	}

	identical
}

throsExceptionFun() {
	throw "out of llamas";
//	throw Exception("out of llamas");
}

runTest() {
	// testBool();
	// testContainer();
//	testFun();
//	testAnonymousFun();
//testOperation();
testException();
}